//
//  NewCaseDetailViewController.m
//  MyDIYHouse
//
//  Created by dlios on 15-7-3.
//  Copyright (c) 2015年 李平洋. All rights reserved.
//

#import "NewCaseDetailViewController.h"
#import "CaseDetailCell.h"
#import "UIImageView+WebCache.h"


@interface NewCaseDetailViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,retain)UITableView *CaseDetailTableView;
//创建一个headerView
@property(nonatomic,retain)UIView *headerView;

//用户头像
@property(nonatomic,retain)UIView *userImageBackgroundView;
@property(nonatomic,retain)UIImageView *userImageImageView;
//创建一个装修案例标题View
@property(nonatomic,retain)UIView *caseDetailTitleView;
//设计名
@property(nonatomic,retain)UILabel *titleLabel;
//设计师名
@property(nonatomic,retain)UILabel *userNameTitleLabel;
@property(nonatomic,retain)UILabel *userNameLabel;
//风格
@property(nonatomic,retain)UILabel *styleShowTitleLabel;
@property(nonatomic,retain)UILabel *styleShowNameLabel;
//户型
@property(nonatomic,retain)UILabel *typeShowTitleLabel;
@property(nonatomic,retain)UILabel *typeShowNameLabel;
//面积
@property(nonatomic,retain)UILabel *areaShowTitleLabel;
@property(nonatomic,retain)UILabel *areaShowNameLabel;
//预算
@property(nonatomic,retain)UILabel *costShowTitleLabel;
@property(nonatomic,retain)UILabel *costShowNameLabel;

@end

@implementation NewCaseDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.CaseDetailTableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-64-49) style:UITableViewStylePlain];
    //
    self.CaseDetailTableView.backgroundColor=[UIColor lightGrayColor];
    [self.view addSubview:self.CaseDetailTableView];
    self.CaseDetailTableView.rowHeight = 320;
    self.CaseDetailTableView.dataSource = self;
    self.CaseDetailTableView.delegate = self;
    self.CaseDetailTableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    //创建headview
    self.headerView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];
    self.headerView.backgroundColor=[UIColor blackColor];
    
    //在headerView上创建三个View,用户头像:userImageBackgroundView,案例详情标题:caseDetailTitleView,案例描述:caseDescriptionView
    //用户头像背景:userImageBackgroundView
    self.userImageBackgroundView=[[UIView alloc]initWithFrame:CGRectMake(5, 5, self.view.frame.size.width/4-10, self.view.frame.size.width/4-10)];
    self.userImageBackgroundView.backgroundColor=[UIColor whiteColor];
    [self.headerView addSubview:self.userImageBackgroundView];
    [self.userImageBackgroundView release];
    //案例详情标题背景:caseDetailTitleView
    self.caseDetailTitleView=[[UIView alloc]initWithFrame:CGRectMake(self.view.frame.size.width/4+5, 5, self.view.frame.size.width/4*3-10, 130)];
    self.caseDetailTitleView.backgroundColor=[UIColor whiteColor];
    [self.headerView addSubview:self.caseDetailTitleView];
    [self.caseDetailTitleView release];
    //    //案例描述背景:caseDescriptionView
    //    self.caseDescriptionView=[[UIView alloc]initWithFrame:CGRectMake(5, 150, self.view.frame.size.width-10, 175)];
    //    self.caseDescriptionView.backgroundColor=[UIColor whiteColor];
    //    [self.headerView addSubview:self.caseDescriptionView];
    //    [self.caseDescriptionView release];
    //在用户头像背景上铺userImageImageView
    self.userImageImageView = [[UIImageView alloc]initWithFrame:CGRectMake(5, 6, self.view.frame.size.width/4-20, self.view.frame.size.width/4-20)];
    self.userImageImageView.backgroundColor=[UIColor blackColor];
    NSDictionary *userDic = self.myCase.user;
    [self.userImageImageView sd_setImageWithURL:[NSURL URLWithString:[[userDic objectForKey:@"userImage"] objectForKey:@"large"]]];
    
    
    [self.userImageBackgroundView addSubview:self.userImageImageView];
    //在案例详情标题背景上铺label
    //标题
    self.titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(10, 10, self.view.frame.size.width-20, 20)];
    self.titleLabel.font=[UIFont systemFontOfSize:18];
    [self.titleLabel setTextAlignment:0];
    self.titleLabel.textColor=[UIColor blackColor];
    self.titleLabel.text = self.myCase.title;
    
    
    
    [self.caseDetailTitleView addSubview:self.titleLabel];
    //设计师标题
    self.userNameTitleLabel=[[UILabel alloc]initWithFrame:CGRectMake(10, 40, self.view.frame.size.width/4-30, 20)];
    //    self.userNameTitleLabel.backgroundColor=[UIColor yellowColor];
    self.userNameTitleLabel.text=@"设计师:";
    [self.userNameTitleLabel setTextAlignment:NSTextAlignmentRight];
    self.userNameTitleLabel.font=[UIFont systemFontOfSize:15];
    [self.caseDetailTitleView addSubview:self.userNameTitleLabel];
    //设计师名字
    self.userNameLabel=[[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width/4-30+15, 40, self.view.frame.size.width/3-70, 20)];
    self.userNameLabel.font=[UIFont systemFontOfSize:15];
    self.userNameLabel.textColor=[UIColor cyanColor];
    
    self.userNameLabel.text = [userDic objectForKey:@"userName"];
    [self.caseDetailTitleView addSubview:self.userNameLabel];
    //风格标题
    self.styleShowTitleLabel=[[UILabel alloc]initWithFrame:CGRectMake(10, 70, self.view.frame.size.width/4-30, 20)];
    //    self.styleShowTitleLabel.backgroundColor=[UIColor yellowColor];
    self.styleShowTitleLabel.text=@"风格:";
    [self.styleShowTitleLabel setTextAlignment:NSTextAlignmentRight];
    self.styleShowTitleLabel.font=[UIFont systemFontOfSize:15];
    [self.caseDetailTitleView addSubview:self.styleShowTitleLabel];
    //风格名称
    self.styleShowNameLabel=[[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width/4-30+15, 70, self.view.frame.size.width/3-70, 20)];
    self.styleShowNameLabel.font=[UIFont systemFontOfSize:15];
    self.styleShowNameLabel.textColor=[UIColor cyanColor];
    //    self.styleShowNameLabel.backgroundColor=[UIColor yellowColor];
    [self.caseDetailTitleView addSubview:self.styleShowNameLabel];
    //面积标题
    self.areaShowTitleLabel=[[UILabel alloc]initWithFrame:CGRectMake(10, 100, self.view.frame.size.width/4-30, 20)];
    self.areaShowTitleLabel.font=[UIFont systemFontOfSize:15];
    //    self.areaShowTitleLabel.backgroundColor=[UIColor yellowColor];
    self.areaShowTitleLabel.text=@"面积:";
    [self.areaShowTitleLabel setTextAlignment:NSTextAlignmentRight];
    [self.caseDetailTitleView addSubview:self.areaShowTitleLabel];
    //面积大小
    self.areaShowNameLabel=[[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width/4-30+15, 100, self.view.frame.size.width/3-70, 20)];
    self.areaShowNameLabel.font=[UIFont systemFontOfSize:12];
    self.areaShowNameLabel.textColor=[UIColor cyanColor];
    //    self.areaShowNameLabel.backgroundColor=[UIColor yellowColor];
    [self.caseDetailTitleView addSubview:self.areaShowNameLabel];
    
    //户型标题
    self.typeShowTitleLabel=[[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width/4+50, 70, self.view.frame.size.width/4-30, 20)];
    self.typeShowTitleLabel.font=[UIFont systemFontOfSize:15];
    //    self.typeShowTitleLabel.backgroundColor=[UIColor yellowColor];
    self.typeShowTitleLabel.text=@"户型:";
    [self.typeShowTitleLabel setTextAlignment:NSTextAlignmentRight];
    [self.caseDetailTitleView addSubview:self.typeShowTitleLabel];
    //户型名称
    self.typeShowNameLabel=[[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width/4+50+self.view.frame.size.width/4-25, 70, self.view.frame.size.width/3-70, 20)];
    self.typeShowNameLabel.font=[UIFont systemFontOfSize:15];
    self.typeShowNameLabel.textColor=[UIColor cyanColor];
    
    //    self.typeShowNameLabel.backgroundColor=[UIColor yellowColor];
    [self.caseDetailTitleView addSubview:self.typeShowNameLabel];
    
    
    //预算标题
    self.costShowTitleLabel=[[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width/4+50, 100, self.view.frame.size.width/4-30, 20)];
    self.costShowTitleLabel.font=[UIFont systemFontOfSize:15];
    //    self.costShowTitleLabel.backgroundColor=[UIColor yellowColor];
    self.costShowTitleLabel.text=@"预算:";
    [self.costShowTitleLabel setTextAlignment:NSTextAlignmentRight];
    [self.caseDetailTitleView addSubview:self.costShowTitleLabel];
    //预算多少
    self.costShowNameLabel=[[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width/4+50+self.view.frame.size.width/4-25, 100, self.view.frame.size.width/3-70, 20)];
    self.costShowNameLabel.font=[UIFont systemFontOfSize:11];
    self.costShowNameLabel.textColor=[UIColor cyanColor];
    //    self.costShowNameLabel.backgroundColor=[UIColor yellowColor];
    [self.caseDetailTitleView addSubview:self.costShowNameLabel];
    //在案例描述背景放上案例描述label
    
    
    
    
    
    
    self.CaseDetailTableView.tableHeaderView=self.headerView;
    
    [_headerView release];
    [_CaseDetailTableView release];
    
    
    self.styleShowNameLabel.text=self.myCase.styleShow;
    self.typeShowNameLabel.text=self.myCase.typeShow;
    self.areaShowNameLabel.text=self.myCase.areaShow;
    self.costShowNameLabel.text=self.myCase.costShow;
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.myCase.photos.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *reuse=@"reuse";
    CaseDetailCell *cell=[tableView dequeueReusableCellWithIdentifier:reuse];
    if (!cell) {
        cell=[[[CaseDetailCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse] autorelease];
    }
    
    
    NSDictionary *tempPicDic = self.myCase.photos[indexPath.row];
    
    
    NSNumber *picId=[tempPicDic objectForKey:@"id"];
    // NSNumber *picWidth=[tempPicDic objectForKey:@"width"];
    // NSNumber *picHeight=[tempPicDic objectForKey:@"height"];
    
    // NSString *picUrl=[NSString stringWithFormat:@"http://gooju.cn/dimages/%@_0_w%@_h%@_m0.jpg",picId,picWidth,picHeight];
    
    NSString *picUrl=[NSString stringWithFormat:@"http://gooju.cn/dimages/%@_0_w375_h200_m0.jpg",picId];
    
    NSLog(@"%@",picUrl);
    
    
    [cell.furniturePictureView sd_setImageWithURL:[NSURL URLWithString:picUrl]];
    
    return cell;
    
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
